class Solution:
    def soupServings(self, n: int) -> float:
        if n >= 4451:
            return 1
        
        @cache # 缓存装饰器，避免重复计算 dfs（一行代码实现记忆化）
        def dfs(a, b):
            if a<=0 and b <= 0:
                return 0.5
            if a <= 0:
                return 1.0
            if b <= 0:
                return 0.0
            return (0.25 * (dfs(a - 100, b) + dfs(a - 75, b - 25) + dfs(a - 50, b - 50) + dfs(a - 25, b - 75)))
        
        return dfs(n, n)